1733B - Rule of League - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n, x, y = map(int, input().split())
    if (bool(x) ^ bool(y)) and not ((n-1) % max(x, y)):
        x = max(x, y)
        ans = [1]*x
        for i in range(x, n-1, x):
            ans += [i+2]*x
        print(*ans)
    else:
        print('-1')

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 33
int main(){
  int test;cin>>test;
  while(test--){
    int n,s,k;cin>>n>>s>>k;
    if(s!=0&&k!=0){
      cout<<-1<<endl;
      continue;
    }
    if(s==0&&k==0){
      cout<<-1<<endl;
      continue;
    }
    if(s>k)swap(s,k);
    if((n-1)%k){
      cout<<-1<<endl;
      continue;
    }
    for(int i=2;i<=n;i+=k){
      for(int j=0;j<k;j++)cout<<i<<" ";
      
    }cout<<endl;
  }
}


Comments

Submit
0 Comments
More Questions

1525D - Armchairs
1257A - Two Rival Students
1415A - Prison Break
1271A - Suits
259B - Little Elephant and Magic Square
1389A - LCM Problem
778A - String Game
1382A - Common Subsequence
1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection
2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes
371A - K-Periodic Array
1542A - Odd Set